<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .line {
        stroke: #ccc;
        stroke-width: 2px;
      }
      .text {
        font-size: 12px;
        text-anchor: middle;
        dominant-baseline: middle;
      }
    </style>
  </head>
  <body>
    <script src="../d3.js"></script>
    <script>
      const domain = [11, 155];
      const range = [0, 600];
      const width = 800;
      const height = 400;
      const margin = 100;

      const x = d3.scaleLinear().domain(domain).range(range).nice();

      const svgSelection = d3.select("body").append("svg");
      svgSelection.attr("width", width);
      svgSelection.attr("height", height);

      const g = svgSelection
        .append("g")
        .attr("transform", `translate(${margin},${height - margin})`);

      g.call((g) => {
        g.append("line")
          .attr("x1", 0)
          .attr("y1", 0)
          .attr("x2", range[1])
          .attr("y2", 0)
          .attr("class", "line");
      });

      const ticks = x.ticks();

      const gs = g
        .selectAll("g")
        .data(ticks)
        .join("g")
        .call((g) => {
          g.append("line")
            .attr("x1", (d) => x(d))
            .attr("y1", 0)
            .attr("x2", (d) => x(d))
            .attr("y2", 10)
            .attr("class", "line");
        })
        .call((g) => {
          g.append("text")
            .attr("x", (d) => x(d))
            .attr("y", 20)
            .text((d) => d)
            .attr("class", "text");
        });
    </script>
  </body>
</html>
